package com.bw.util;

import com.bw.bean.Dept;
import com.bw.service.DeptService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;
import java.sql.SQLOutput;
import java.util.ArrayList;
import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("classpath:spring-context.xml")
public class MyTest {

    @Resource
    private DeptService deptService;

    @Test
    public void test(){
        for (int i=0;i<10;i++){
            Dept dept = new Dept();
            dept.setParent_id(1);
            dept.setDept_name("技术"+i);
            dept.setOrder_num(1);
            dept.setLeader("李四"+i);
            dept.setPhone("13452225488");
            dept.setEmail("3325422556@qq.com");
            dept.setStatus("0");
            dept.setDel_flag("0");
            deptService.save(dept);
        }

    }

    @Test
    public void test1(){
        ArrayList<Dept> list = new ArrayList<>();
        for (int i=0;i<5;i++){
            Dept dept = new Dept();
            dept.setParent_id(1);
            dept.setDept_name("社交"+i);
            dept.setOrder_num(1);
            dept.setLeader("李四"+i);
            dept.setPhone("13452225488");
            dept.setEmail("3325422556@qq.com");
            dept.setStatus("0");
            dept.setDel_flag("0");
            list.add(dept);
        }
        deptService.saveBatch(list);
    }


    @Test
    public void test2(){
        Dept dept = new Dept();
        dept.setParent_id(1);
        dept.setDept_name("社交");
        dept.setOrder_num(1);
        dept.setLeader("李四");
        dept.setPhone("13452225488");
        dept.setEmail("3325422556@qq.com");
        dept.setStatus("0");
        dept.setDel_flag("0");


        dept.setDept_id(1);
        deptService.updateById(dept);
        System.out.println(dept);
    }

    @Test
    public void test3(){
        Dept dept = new Dept();

        dept.setStatus("1");
        dept.setDept_id(1);
        deptService.updateStatusById(dept);
        System.out.println(dept);
    }

    @Test
    public void test4(){
        Dept dept = new Dept();
        dept.setDept_name("2");

        List<Dept> listByName = deptService.getListByName(dept);
        System.out.println(listByName);
    }
    @Test
    public void test5(){


        List<Dept> listByName = deptService.getListByParentId(0);
        System.out.println(listByName);
    }

    @Test
    public void test6(){
        Dept dept = new Dept();
        dept.setDept_id(133);
        dept.setDel_flag("2");
        deptService.deleteById(dept);
        System.out.println(dept);
    }



}
